package com.vancouver.knows.business.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.pangu.util.StringUtil;
import com.vancouver.knows.business.bean.UserInfo;
import com.vancouver.knows.business.bean.UserPostDetailInfo;

/**
 * 用户查询列表解析
 * Created by llf
 */
public class QueryUserInfoHandler extends ACheckableJsonParser{

	private UserInfo userInfo = null;
	@Override
	protected void parserContent(JSONObject content) throws Exception {
		//String posts = content.getString("user_data");
		//userInfo = JSON.parseObject(posts, UserInfo.class);
		JSONObject jsonPostResult = content.getJSONObject("user_data");
		userInfo = new UserInfo();
		if (jsonPostResult != null) {
			//===========用户信息===========
			userInfo.setUserID(jsonPostResult.getString("user_id"));
			userInfo.setName(jsonPostResult.getString("display_name"));
			userInfo.setUserPostsCount(jsonPostResult.getString("userposts_count"));
			userInfo.setUserPostsWatchingCount(jsonPostResult.getString("userposts_watching_count"));
			userInfo.setTotalUnReadPostComment(jsonPostResult.getString("total_unread_post_comment"));
			userInfo.setTotalUnReadComment(jsonPostResult.getString("total_unread_comment"));
			userInfo.setRegisterDate(jsonPostResult.getString("register_date"));

			String userMeta = jsonPostResult.getString("user_meta");
			if (!StringUtil.isEmptyString(userMeta)) {
				userInfo.setUserMeta(JSON.parseObject(userMeta, UserInfo.UserMeta.class));
			}

			String registerType = jsonPostResult.getString("register_type");
			if (!StringUtil.isEmptyString(registerType)) {
				userInfo.setRegisterType(JSON.parseObject(registerType, UserInfo.RegisterType.class));
			}
			//============积分详情信息=================
			String userPointsDetailString = jsonPostResult.getString("user_points_detail");
			if (!StringUtil.isEmptyString(userPointsDetailString)) {
				userInfo.userPointsDetailsInfo = JSON.parseObject(userPointsDetailString, UserInfo.UserPointsDetailsInfo.class);
			}
		}
		
	}
	public UserInfo getUserInfo(){
		return userInfo;
	}

}
